package c.x.jy.api.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import c.x.jy.common.utils.AESUtil;
import c.x.jy.common.utils.QrCodeUtil;
import c.x.jy.common.utils.R;
import c.x.jy.service.comm.CommonService;
import c.x.jy.service.config.BusinessConfigService;

@RestController
@RequestMapping("api/comm")
public class CommController {

	@Autowired
	private CommonService commonService;
	@Autowired
	private Environment env;
	@Autowired
	private BusinessConfigService businessConfigService;

	@RequestMapping("/areaList")
	public R areaList() {

		return R.ok().put("data", commonService.areaList());

	}

	@RequestMapping("/qrCode")
	public void qrCode(String bcode,String mcode, HttpServletResponse response) {
		// AESUtil.AESEncode(code, env.getProperty("smartlock.secret"))

		QrCodeUtil.getQrCode(
				env.getProperty("smartlock.baseUrl") + env.getProperty("smartlock.wechatUrl")==null?"":env.getProperty("smartlock.wechatUrl")
						+ "wechat/tologin?bcode=" + bcode+"&mcode="+mcode,
				response);
	}

	@RequestMapping("/adv")
	public R adv() {

		String adv = businessConfigService.getBusinessConfigValue(null, "AGENT_DEVICE_ADV");
		return R.put(adv);
	}

}
